// src/stores/categoryStore.ts
import { defineStore } from 'pinia';
import type{ Category } from '@/common/types/category';
import {getCategory} from "@/common/net/api";
import {ElMessage} from "element-plus";

export const useCategoryStore = defineStore('category', {
  state: () => ({
    categories: [] as Category[],
    isLoaded: false,
  }),
  actions: {
    async fetchCategories() {
      try {
        await getCategory().then(res=>{
          if (res.data.state){
            this.categories = res.data.data;
            this.isLoaded = true;
          }
        })
      } catch (error) {
        console.error('Error fetching categories:', error);
      }
    },
  },
});
